<?php
    
    include_once '../../controlador/php/conexion/Conexion10.php';
    $con = new Conexion10();
    
    $pac = $_REQUEST['pac'];
    $deteccion = "SELECT
                TOP 1 HCFECFOL, AINCONSEC, PACNUMDOC, PACPRINOM, PACSEGNOM, PACPRIAPE, PACSEGAPE,
                LTRIM(RTRIM(PACPRINOM+' '+PACSEGNOM+' '+PACPRIAPE+' '+PACSEGAPE))AS NOMBRES,
                CONVERT(nvarchar(5), HCCM09N20)	AS	'_12',
                CONVERT(nvarchar(5), HCCM09N12)	AS	'_13',
                CONVERT(nvarchar(5), HCCM09N18)	AS	'_14',
                CONVERT(nvarchar(5), HCCM09N31)	AS	'_22',
                CONVERT(nvarchar(5), HCCM09N32)	AS	'_23',
                CONVERT(nvarchar(100), HCCM03N58)AS	'_23cada',
                CONVERT(nvarchar(5), HCCM09N33)	AS	'_24',
                CONVERT(nvarchar(100), HCCM03N59)AS	'_24cada',
                CONVERT(nvarchar(5), HCCM09N30)	AS	'_25',
                CONVERT(nvarchar(100), HCCM03N60)AS	'_25cada',
                CONVERT(nvarchar(5), HCCM09N46)	AS	'_26',
                CONVERT(nvarchar(100), HCCM03N61)AS	'_26cuantos',
                CONVERT(nvarchar(5), HCCM09N36)	AS	'_27',
                CONVERT(nvarchar(100), HCCM03N62)AS	'_27cual',
                CONVERT(nvarchar(5), HCCM09N45)	AS	'_28',
                CONVERT(nvarchar(5), HCCM09N40)	AS	'_29',
                CONVERT(nvarchar(100), HCCM03N63)AS	'_29donde',
                CONVERT(nvarchar(5), HCCM09N42)	AS	'_30',
                CONVERT(nvarchar(5), HCCM09N37)	AS	'_31',
                CONVERT(nvarchar(100), HCCM03N64)AS	'_31cual',
                CONVERT(nvarchar(5), HCCM09N39)	AS	'_32',
                CONVERT(nvarchar(100), HCCM03N65)AS	'_32cada',
                CONVERT(nvarchar(1000), HCCM03N44)	AS	'_34'
                FROM HCMHODETE
                INNER JOIN HCNFOLIO ON HCMHODETE.HCNFOLIO = HCNFOLIO.OID
                INNER JOIN HCNTIPHIS ON HCNFOLIO.HCNTIPHIS = HCNTIPHIS.OID
                INNER JOIN ADNINGRESO ON HCNFOLIO.ADNINGRESO = ADNINGRESO.OID
                INNER JOIN GENPACIEN ON ADNINGRESO.GENPACIEN = GENPACIEN.OID
                WHERE
                HCCODIGO='HODETE'
                AND PACNUMDOC = '".$pac."'
                ORDER BY HCFECFOL DESC";
    $res = $con->query($deteccion);
    
    while ($res2 = mssql_fetch_array($res)){
        
        $lista[] = array_map(utf8_encode,$res2);
    }
    
     print_r(json_encode($lista));
    
    $con->cerrarConexion();
    
?>